package com.itheima.springbootwebtlias.service.Impl;

import com.itheima.springbootwebtlias.mapper.ClazzMapper;
import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReporyServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public Map jobCount() {
        List<Map> jobList = empMapper.JobCount();

        Map map = new HashMap();
        map.put("jobList", jobList.stream().map(a-> a.get("name")).collect(Collectors.toList()));
        map.put("dataList", jobList.stream().map(a-> a.get("value")).collect(Collectors.toList()));


        return map;
    }

    @Override
    public List<Map> genderCount() {
        List<Map> list = empMapper.genderCount();

        return list;
    }

    @Override
    public List<Map> selectDegree() {
        List<Map> list = studentMapper.selectDegree();
        return list;
    }

    @Override
    public Map selectCountData() {

        List<Map> list = clazzMapper.selectCountData();

        Map map = new HashMap();
        map.put("clazzList",list.stream().map(name -> name.get("name")).collect(Collectors.toList()) );
        map.put("dataList",list.stream().map(value -> value.get("value")).collect(Collectors.toList()) );

        return map;
    }
}
